//
//  SchoolNewsCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/10/22.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class SchoolNewsCell: UICollectionViewCell {
    
    var model : SchoolNewsModel! {
        didSet{
            getData()
        }
    }
    
    fileprivate let imageView = UIImageView()
    fileprivate let titleLabel = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: .zero)
        
        self.contentView.addSubview(imageView)
        
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        titleLabel.textAlignment = .center
        self.contentView.addSubview(titleLabel)
        
        imageView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 150))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(imageView.snp.bottom)
            make.left.right.equalTo(imageView)
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 刷新数据
    fileprivate func getData() {
        
        var imageUrl = ""
        
        if (model.image?.contains("http"))! {
            imageUrl = model.image ?? ""
        }else{
            imageUrl = kmHttps + (model.image ?? "")
        }
        
        imageView.setUrlImage(with: imageUrl, placeholder: UIImage.imageWithName("loading"))
        titleLabel.text = model.title
    }
}
